<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>BrokenIRC: server_src/rfc_cmds1.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">BrokenIRC
   &#160;<span id="projectnumber">0.0.42</span>
   </div>
   <div id="projectbrief">A &#39;not so functionnal&#39; irc server and a WIP client</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_20e5c1c74b8b955148e6b35ac4a0bc4d.html">server_src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">rfc_cmds1.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="rfc__cmds1_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment">** EPITECH PROJECT, 2018</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">** MY_IRC</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment">** File description:</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment">** my_irc server rfc methods functions</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment">*/</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#include &lt;unistd.h&gt;</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#include &quot;../include/server.h&quot;</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;</div><div class="line"><a name="l00018"></a><span class="lineno"><a class="line" href="rfc__cmds1_8c.html#a67423079c85c9a88a611514cd9558865">   18</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">char</span>     *<a class="code" href="rfc__cmds1_8c.html#a67423079c85c9a88a611514cd9558865">get_full_msg</a>(<span class="keywordtype">char</span> **args)</div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;{</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;        <span class="keywordtype">char</span> *msg = malloc(<a class="code" href="server_8h.html#a6821bafc3c88dfb2e433a095df9940c6">BUF_SIZE</a>);</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;        memset(msg, 0, <a class="code" href="server_8h.html#a6821bafc3c88dfb2e433a095df9940c6">BUF_SIZE</a>);</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 2; args[i]; ++i) {</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;                strcat(msg, args[i]);</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;                strcat(msg, <span class="stringliteral">&quot; &quot;</span>);</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;        }</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;        <span class="keywordflow">return</span> (msg);</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;}</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;</div><div class="line"><a name="l00030"></a><span class="lineno"><a class="line" href="rfc__cmds1_8c.html#aaf538656f62d920ed911f41ea4a0f186">   30</a></span>&#160;<span class="keywordtype">void</span>    *<a class="code" href="rfc__cmds1_8c.html#aaf538656f62d920ed911f41ea4a0f186">broadcast_msg</a>(<a class="code" href="structt__channel.html">t_channel</a> *reqchan, <span class="keywordtype">char</span> **message, <span class="keywordtype">int</span> clifd)</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;{</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;        <a class="code" href="structt__userlist.html">t_userlist</a> *broadcast_list =  reqchan ? reqchan-&gt;<a class="code" href="structt__channel.html#a8097607fae5d78c98125bac6caaefe18">users</a> : NULL;</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;        <span class="keywordflow">if</span> (broadcast_list)</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;                <span class="keywordflow">for</span> (<a class="code" href="structt__userlist.html">t_userlist</a> *tmp = broadcast_list; tmp; tmp = tmp-&gt;<a class="code" href="structt__userlist.html#a3b987a9a352379a703da737198b42d4a">next</a>) {</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;                        <span class="keywordflow">if</span> (tmp-&gt;user-&gt;clifd != clifd) {</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;                        dprintf(tmp-&gt;user-&gt;clifd, <span class="stringliteral">&quot;:%s PRIVMSG %s %s\r\n&quot;</span>,</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;                        message[1], message[2], message[0]);</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;                        }</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;                }</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;        <span class="keywordflow">return</span> (NULL);</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;}</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;</div><div class="line"><a name="l00054"></a><span class="lineno"><a class="line" href="server_8h.html#aa5da766def7467ba7a3899fddbfcd278">   54</a></span>&#160;<span class="keywordtype">void</span>    *<a class="code" href="rfc__cmds1_8c.html#aa5da766def7467ba7a3899fddbfcd278">privmsg</a>(<a class="code" href="server_8h.html#acfbe918d8821ff3d1d8dc2c90bb8f6a2">cmdargs</a> args, <span class="keywordtype">int</span> clifd, <a class="code" href="structt__channel.html">t_channel</a> *chans)</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;{</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;        <a class="code" href="structt__user.html">t_user</a> *from = <a class="code" href="lists__helpers_8c.html#a0195cd48a4c52a9624a811825cef8afb">find_user_by_fd</a>(chans-&gt;<a class="code" href="structt__channel.html#a8097607fae5d78c98125bac6caaefe18">users</a>, clifd);</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;        <a class="code" href="structt__channel.html">t_channel</a> *reqchan = <a class="code" href="lists__helpers_8c.html#ae86be37e5d76544c9d6feb9d7b9b6b02">get_chan_by_name</a>(chans, args[1]);</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;        <a class="code" href="structt__user.html">t_user</a> *to = reqchan ? NULL : <a class="code" href="lists__helpers_8c.html#a7ebf668b9cfc31f3b29114dfed75c0ad">find_user_by_name</a>(args[1], chans-&gt;<a class="code" href="structt__channel.html#a8097607fae5d78c98125bac6caaefe18">users</a>);</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        <span class="keywordtype">char</span> *message[3] = { <a class="code" href="rfc__cmds1_8c.html#a67423079c85c9a88a611514cd9558865">get_full_msg</a>(args), from-&gt;<a class="code" href="structt__user.html#ae26ce5e41546b895d8d85f3cde41c096">nick</a>, args[1] };</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;        <span class="keywordflow">if</span> (reqchan) {</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;                <a class="code" href="rfc__cmds1_8c.html#aaf538656f62d920ed911f41ea4a0f186">broadcast_msg</a>(reqchan, message, clifd);</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (to) {</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;                dprintf(to-&gt;<a class="code" href="structt__user.html#a29a8abb5e21ec4d86ce72c756b6b43e4">clifd</a>, <span class="stringliteral">&quot;:%s PRIVMSG %s %s\r\n&quot;</span>,</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;                        message[1], message[2], message[0]);</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;        }</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;        free(message[0]);</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        <span class="keywordflow">return</span> (chans);</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;}</div><div class="ttc" id="rfc__cmds1_8c_html_a67423079c85c9a88a611514cd9558865"><div class="ttname"><a href="rfc__cmds1_8c.html#a67423079c85c9a88a611514cd9558865">get_full_msg</a></div><div class="ttdeci">static char * get_full_msg(char **args)</div><div class="ttdef"><b>Definition:</b> <a href="rfc__cmds1_8c_source.html#l00018">rfc_cmds1.c:18</a></div></div>
<div class="ttc" id="structt__userlist_html"><div class="ttname"><a href="structt__userlist.html">t_userlist</a></div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00114">server.h:114</a></div></div>
<div class="ttc" id="lists__helpers_8c_html_a0195cd48a4c52a9624a811825cef8afb"><div class="ttname"><a href="lists__helpers_8c.html#a0195cd48a4c52a9624a811825cef8afb">find_user_by_fd</a></div><div class="ttdeci">t_user * find_user_by_fd(t_userlist *list, int clifd)</div><div class="ttdef"><b>Definition:</b> <a href="lists__helpers_8c_source.html#l00026">lists_helpers.c:26</a></div></div>
<div class="ttc" id="structt__channel_html_a8097607fae5d78c98125bac6caaefe18"><div class="ttname"><a href="structt__channel.html#a8097607fae5d78c98125bac6caaefe18">t_channel::users</a></div><div class="ttdeci">t_userlist * users</div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00123">server.h:123</a></div></div>
<div class="ttc" id="structt__user_html"><div class="ttname"><a href="structt__user.html">t_user</a></div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00105">server.h:105</a></div></div>
<div class="ttc" id="structt__channel_html"><div class="ttname"><a href="structt__channel.html">t_channel</a></div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00121">server.h:121</a></div></div>
<div class="ttc" id="server_8h_html_acfbe918d8821ff3d1d8dc2c90bb8f6a2"><div class="ttname"><a href="server_8h.html#acfbe918d8821ff3d1d8dc2c90bb8f6a2">cmdargs</a></div><div class="ttdeci">char ** cmdargs</div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00044">server.h:44</a></div></div>
<div class="ttc" id="lists__helpers_8c_html_ae86be37e5d76544c9d6feb9d7b9b6b02"><div class="ttname"><a href="lists__helpers_8c.html#ae86be37e5d76544c9d6feb9d7b9b6b02">get_chan_by_name</a></div><div class="ttdeci">t_channel * get_chan_by_name(t_channel *list, char *channame)</div><div class="ttdef"><b>Definition:</b> <a href="lists__helpers_8c_source.html#l00044">lists_helpers.c:44</a></div></div>
<div class="ttc" id="rfc__cmds1_8c_html_aaf538656f62d920ed911f41ea4a0f186"><div class="ttname"><a href="rfc__cmds1_8c.html#aaf538656f62d920ed911f41ea4a0f186">broadcast_msg</a></div><div class="ttdeci">void * broadcast_msg(t_channel *reqchan, char **message, int clifd)</div><div class="ttdef"><b>Definition:</b> <a href="rfc__cmds1_8c_source.html#l00030">rfc_cmds1.c:30</a></div></div>
<div class="ttc" id="server_8h_html_a6821bafc3c88dfb2e433a095df9940c6"><div class="ttname"><a href="server_8h.html#a6821bafc3c88dfb2e433a095df9940c6">BUF_SIZE</a></div><div class="ttdeci">#define BUF_SIZE</div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00024">server.h:24</a></div></div>
<div class="ttc" id="structt__user_html_a29a8abb5e21ec4d86ce72c756b6b43e4"><div class="ttname"><a href="structt__user.html#a29a8abb5e21ec4d86ce72c756b6b43e4">t_user::clifd</a></div><div class="ttdeci">int clifd</div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00106">server.h:106</a></div></div>
<div class="ttc" id="structt__userlist_html_a3b987a9a352379a703da737198b42d4a"><div class="ttname"><a href="structt__userlist.html#a3b987a9a352379a703da737198b42d4a">t_userlist::next</a></div><div class="ttdeci">struct s_userlist * next</div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00117">server.h:117</a></div></div>
<div class="ttc" id="rfc__cmds1_8c_html_aa5da766def7467ba7a3899fddbfcd278"><div class="ttname"><a href="rfc__cmds1_8c.html#aa5da766def7467ba7a3899fddbfcd278">privmsg</a></div><div class="ttdeci">void * privmsg(cmdargs args, int clifd, t_channel *chans)</div><div class="ttdef"><b>Definition:</b> <a href="rfc__cmds1_8c_source.html#l00054">rfc_cmds1.c:54</a></div></div>
<div class="ttc" id="lists__helpers_8c_html_a7ebf668b9cfc31f3b29114dfed75c0ad"><div class="ttname"><a href="lists__helpers_8c.html#a7ebf668b9cfc31f3b29114dfed75c0ad">find_user_by_name</a></div><div class="ttdeci">t_user * find_user_by_name(const char *name, t_userlist *usrs)</div><div class="ttdef"><b>Definition:</b> <a href="lists__helpers_8c_source.html#l00072">lists_helpers.c:72</a></div></div>
<div class="ttc" id="structt__user_html_ae26ce5e41546b895d8d85f3cde41c096"><div class="ttname"><a href="structt__user.html#ae26ce5e41546b895d8d85f3cde41c096">t_user::nick</a></div><div class="ttdeci">char * nick</div><div class="ttdef"><b>Definition:</b> <a href="server_8h_source.html#l00108">server.h:108</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
